
function _(id){
	return document.getElementById(id);
}

var Ui = {};

Ui.SelectBox = function() {
    this.current = -1;
    this.aSelectBox = [];
};

Ui.SelectBox.prototype = {
	add : function(id) {
		this.aSelectBox.push(id);
	},

	setCurrnet : function(id) {
		var i = 0;
		var n = this.aSelectBox.length;
		while(i < n){
			this.current = i;
			if (this.aSelectBox[i++] == id){
				return;
			}
		}

		this.current = -1;
	},

	getCurSel : function(){
		var selBox = _(this.aSelectBox[this.current]);
		var i = -1;
		var n = selBox.length;
		while(++i < n){
			var option = selBox.getElementsByTagName("OPTION")[i];
			if (option.selected) {
				return i;
			}
		}
		return -1;
	},

	getPos : function(id) {
		var i = 0;
		var n = this.aSelectBox.length;
		while(i < n){
			if (this.aSelectBox[i++] == id){
				return i;
			}
		}
		return -1;
	},

	getBox : function(pos) {
		switch (pos) {
		case 'front':
			return _(this.aSelectBox[this.current - 1]);
		case 'currnet':
			return _(this.aSelectBox[this.current]);
		case 'next':
			return _(this.aSelectBox[this.current + 1]);
		default:
			return null;
		}
	},

	clearBox : function(id) {
		_(id).length = 1;
		_(id).value = 0;
		_(id)[0].selected = 'selected';
		_(id).style.background = '#999999';
	},

	clearBoxAll : function() {
		var i = 0;
		var n = this.aSelectBox.length;
		while(i < n){
			this.clearBox(this.aSelectBox[i++]);
		}
	},

	clearBoxLowThis : function(id) {
		var n = this.aSelectBox.length;
		var i = this.getPos(id);
		if(i < 0)
			return;

		while(i < n){
			this.clearBox(this.aSelectBox[i++]);
		}
	},

	setBoxOption : function(id, ajOption, setValue) {
		var selectBox = _(id);
		selectBox.style.background = '#FFFFFF';
		selectBox.length = 0;

		if (setValue == null)
			setValue = 0;

		for (var i = 0; i < ajOption.length; i++) {
			var option = document.createElement("OPTION");
			option.text = ajOption[i].text;
			option.value = ajOption[i].value;
			selectBox[i] = option;

			if (setValue == option.value)
				selectBox[i].selected = "selected";
		}
	},

	getBoxOptionIsSelected : function(boxId) {
		var selectBox = _(boxId);
		var maxLength = selectBox.length;
		for (var i = 0; i < maxLength; i++) {
			var option = selectBox.getElementsByTagName("OPTION")[i];
			if (option.selected) {
				return option;
			}
		}
	}
}